package com.elcom.roaming;

import java.io.File;

import com.elcom.roaming.common.config.ConfigModule;
import com.elcom.roaming.module.collection.ModuleCollectionInit;
import com.elcom.roaming.module.synthesis.ModuleSynthesisInit;

public class Main {
	
	public static void main(String[] args) {
		if (args.length == 0) {
			System.err.println("Error: no argument !!!");
			System.err.println("Command ex: java -jar roaming.jar module_name config_folder");
		} else {
			if (args[1] != null){
				File file = new File(args[1]);
				if (!file.exists() || !file.isDirectory()) {
					System.err.println("Config folder is not found: " + args[1]);
				}
				ConfigModule.CONFIG_FOLDER = args[1];
			}

			String module = args[0];
			if (module.equals("synthesis")) {
				runModuleSynthsis();
			} else if (module.equals("collection")) {
				runModuleCollection();
			} else {
				System.err.println("Module name = synthesis | collection");
			}
			
		}
	}
	
	public static void runModuleSynthsis(){
		ConfigModule config = ConfigModule.getInstance();
		config.reloadModuleDirectory("synthesis");
		config.load();
		
		ModuleSynthesisInit module = new ModuleSynthesisInit();
		module.run();
	}
	
	public static void runModuleCollection(){
		// init config
		ConfigModule config = ConfigModule.getInstance();
		config.reloadModuleDirectory("collection");
		config.load();
		
		// init module
		ModuleCollectionInit module = new ModuleCollectionInit();
		module.run();
	}

}
